1. Field of the Invention
The invention relates to nonvolatile memory controller, and more particularly to data writing control of nonvolatile memory memories.
2. Description of the Related Art
Nonvolatile memory memories are non-volatile memories that can be electrically erased and reprogrammed. Nonvolatile memory memories are primarily used in memory cards and USB nonvolatile memory drives for general storage and transfer of data between computers and other digital products. Referring to FIG. 1, a schematic diagram of a host 102 and a nonvolatile memory device 104 storing data for the host 102 is shown. In one embodiment, the host 102 is a computer. The nonvolatile memory device 104 comprises a nonvolatile memory controller 112 and a nonvolatile memory 114. The nonvolatile memory controller 112 acts as an interface between the host 102 and the nonvolatile memory 114 and accesses data stored in the nonvolatile memory 114 for the host 102. When the host 102 wants to store data to the nonvolatile memory device 104, the host 102 transfers data to the nonvolatile memory controller 112, and the nonvolatile memory controller 112 writes the data received from the host 102 to the nonvolatile memory 114. When the host 102 wants to retrieve data from the nonvolatile memory device 104, the nonvolatile memory controller 112 retrieves data from the nonvolatile memory 114 and delivers the retrieved data to the host 102.
The nonvolatile memory device 104 stores data for the host 102. The host 102 therefore may retrieve original data from the nonvolatile memory device 104, slightly amend the original data to obtain new data, and store the new data back to the nonvolatile memory device 104. In the situation, only an amended portion of the new data is different from the original data, and an unchanged portion of the new data and is therefore the same as the original data. A conventional nonvolatile memory controller 112, however, does not differentiate the unchanged data portion from the amended data portion, and directly writes all new data to the nonvolatile memory 114. Because writing of the unchanged data portion requires an extra time period, the whole data writing process is delayed, and performance of the nonvolatile memory device 104 is degraded. In addition, because the unchanged data portion is written twice to the nonvolatile memory 114, a life span of the nonvolatile memory 114 is shortened due to unnecessary duplication of the unchanged data portion.
To avoid the aforementioned disadvantages, a method for writing data to a nonvolatile memory is provided. Referring to FIG. 2, a flowchart of a method 200 for writing data to a nonvolatile memory 114 is shown. The nonvolatile memory controller 112 first receives new data from the host 102 at step 202, and calculates a first error correction code according to the new data at step 203. The nonvolatile memory controller 112 then reads a second error correction code of old data from the nonvolatile memory 114 at step 204, wherein the old data has the same logical address as that of the new data. The nonvolatile memory controller 112 then compares the first error correction code with the second error correction code at step 206. When the first error correction code is identical to the second error correction code at step 208, the new data is determined to be an unchanged data portion and is not written to the nonvolatile memory 114. On the contrary, when the first error correction code is not identical to the second error correction code at step 208, the new data is determined to be an amended data portion, and the nonvolatile memory controller 112 writes the new data to the nonvolatile memory at step 210. If the host 102 sends more new data to the nonvolatile memory controller 112, the nonvolatile memory controller 112 repeats the steps 202˜210 again until all data sent by the host 102 is processed.
The method 200 can differentiate a portion of unchanged data from amended data, thus reducing duplication of unchanged data. The method 200, however, still has disadvantages. First, the nonvolatile memory controller 112 has to read an error correction code of the old data from the nonvolatile memory 114, thus extending a time period required by an entire data writing process and degrading performance of the nonvolatile memory device 104. In addition, even if the old data is different from the new data, the second error correction code of the old data may be the same as the first error correction code of the new data. The nonvolatile memory controller 112 therefore may erroneously skip writing of the new data to the nonvolatile memory 114 according to comparison of the first error correction code and the second error correction code. A new method for writing data to a nonvolatile memory is therefore required.